package ar.edu.unicen.pladema.vc1.practico;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;

import ar.edu.unicen.pladema.vc1.model.GraphicAttributes;

public abstract class PracticoDrawer implements PaintListener {
	protected GraphicAttributes graphicAttributes;
	private GC cgc;
	
	public PracticoDrawer(GraphicAttributes ga) {
		this.graphicAttributes = ga;
	}
	@Override
	public final void paintControl(PaintEvent e) {
		cgc = e.gc;
		
		graphicAttributes
			.add(GraphicAttributes.SIZE_WIDTH, e.width)
			.add(GraphicAttributes.SIZE_HEIGHT, e.height);
		long milis=System.currentTimeMillis();
		paintControlImpl(e);
		long elapsed = System.currentTimeMillis() - milis;
		elapsed = elapsed / 1000;
		graphicAttributes.add(GraphicAttributes.ELAPSED, elapsed);
	}
	protected Color getColor(int r, int g, int b) {
//		try {
			Color cb = new Color(cgc.getDevice(), r, g, b);
			return cb;
//		} catch(Exception e) {
//			System.out.println("Error al crear el color R" + r + " G" + g +" B"+ b);
//		}
//		return new Color(cgc.getDevice(), 255, 255, 255);
	}
	protected abstract void paintControlImpl(PaintEvent e);
}
